#include <stdio.h>
#include <math.h>
#include <string.h>
#include "stm32f10x.h"
#include "bsp_usart.h"
#include "bsp_hx711.h"
#include "bsp_f1012.h"
#include "bsp_timer.h"
#include "DHT20.h"
#include "bsp_systick.h"
#include "stm32f10x_it.h"
#include "stm32f10x_dma.h"
#include "stm32f10x_usart.h"
#include "stm32f10x_exti.h"
extern volatile uint16_t adc_value[2];
extern volatile unsigned long hx711_data[EndHX711];
volatile unsigned long hx711_1s_data[50][EndHX711];
volatile unsigned long hx711_1s_perv[50][EndHX711];
volatile extern int counter_msg;
int counter_perv;
int GloblDataCont = 0;
int GloblDataAll;
char GlobalData[20480];

typedef struct s_m4_element {
    int density_reg;
    int dot_reg;
    float density;
} s_m4_t;
s_m4_t s_m4_o2 = {0, 0};
s_m4_t s_m4_co2 = {0, 0};
typedef struct dht20_element {
    uint32_t CT_data[2];
    volatile int humidity_x10;
    volatile int temperature_x10;
    float humidity;
    float temperature;
} dht20_t;
dht20_t dht20 = {{0}, 0, 0, 0.0, 0.0};
typedef struct g9250_element {
    int data_len;
    float people_temperature;
    int people_x;
    int people_y;
    float matrix[1024 + 1];
    float ic_temperature;
    int spinrtf_start_index;
    short refresh;
} g9250_t;
g9250_t g9250 = {0, 0, 0, 0, {0}};
#define SPRINTF_G9250_MATRIX_MAX 40

extern char cycle_20ms;
char cycle_1s;
int cycle_1s_cnt;
void counter_init() {
    // 配置GPIO为外部中断模式
    GPIO_InitTypeDef GPIO_InitStructure;
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; // 设置为上拉输入模式（或根据你的需求配置）
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    // 配置EXTI线0（连接到PA0）
    EXTI_InitTypeDef EXTI_InitStructure;
    EXTI_InitStructure.EXTI_Line = EXTI_Line0;
    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; // 上升沿触发（或EXTI_Trigger_Falling/EXTI_Trigger_Rising_Falling）
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;
    EXTI_Init(&EXTI_InitStructure);

    // 配置NVIC
    NVIC_InitTypeDef NVIC_InitStructure;
    NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
}
int test;
int main(void) {
    int id = 5;
    SysTick_Init();
    Init_I2C_Sensor_Port();
    usart4_init();
    usart1_init();
    usart2_init();
    usart5_init();
    hx711_init();
    f1012_init();
    timer1_init();
    counter_init();
    if (id == 2) {
        int i, j;
        for (i = 0; i < 2; i++)
            for (j = 0; j < 2; j++);
    } else if (id == 3) {
        int i, j;
        for (i = 0; i < 3; i++)
            for (j = 0; j < 3; j++);
    } else if (id == 4) {
        int i, j;
        for (i = 0; i < 4; i++)
            for (j = 0; j < 4; j++);
    } else if (id == 5) {
        int i, j;
        for (i = 0; i < 5; i++)
            for (j = 0; j < 5; j++);
    } else if (id == 6) {
        int i, j;
        for (i = 0; i < 6; i++)
            for (j = 0; j < 6; j++);
    } else if (id == 7) {
        int i, j;
        for (i = 0; i < 7; i++)
            for (j = 0; j < 7; j++);
    } else if (id == 8) {
        int i, j;
        for (i = 0; i < 8; i++)
            for (j = 0; j < 8; j++);
    } else if (id == 9) {
        int i, j;
        for (i = 0; i < 9; i++)
            for (j = 0; j < 9; j++);
    } else if (id == 10) {
        int i, j;
        for (i = 0; i < 10; i++)
            for (j = 0; j < 10; j++);
    }
    cycle_1s = 0;
    cycle_1s_cnt = 0;
    cycle_20ms = 0;
    // hx711_read_base();
    Delay_ms(500);
    while (1) {
        test = 0;
        while (cycle_20ms == 0) {
            test = 1;
        };
        if (test == 0) {
                     sprintf(GlobalData + strlen(GlobalData), "!!!!!%d!!!!!", cycle_1s_cnt);
                 }
        cycle_20ms = 0;
        cycle_1s_cnt++;
        if (cycle_1s_cnt >= 50) {
            int i;
            cycle_1s = 1;
            cycle_1s_cnt = 0;
            s_m4_o2.density = 0;
            s_m4_o2.dot_reg = 0;
            s_m4_co2.density = 0;
            s_m4_co2.dot_reg = 0;
            counter_perv = counter_msg;
            counter_msg = 0;
            dht20.humidity = 0;
            dht20.temperature = 0;
            for (i = 0; i < 50; i++) {
                hx711_1s_perv[i][HX711_4] = hx711_1s_data[i][HX711_1];
                hx711_1s_perv[i][HX711_5] = hx711_1s_data[i][HX711_2];
                hx711_1s_perv[i][HX711_6] = hx711_1s_data[i][HX711_3];
                hx711_1s_perv[i][HX711_1] = hx711_1s_data[i][HX711_4];
                hx711_1s_perv[i][HX711_2] = hx711_1s_data[i][HX711_5];
                hx711_1s_perv[i][HX711_3] = hx711_1s_data[i][HX711_6];
            }

            for (i = 0; i < 1024; i++) {
                g9250.matrix[i] = 0;
            }
            g9250.data_len = 0;
            g9250.people_temperature = 0;
            g9250.people_x = 0;
            g9250.people_y = 0;
            g9250.ic_temperature = 0;
        } else {
            cycle_1s = 0;
        }
        hx711_read_all();
        hx711_1s_data[cycle_1s_cnt][HX711_1] = hx711_data[HX711_1];
        hx711_1s_data[cycle_1s_cnt][HX711_2] = hx711_data[HX711_2];
        hx711_1s_data[cycle_1s_cnt][HX711_3] = hx711_data[HX711_3];
        hx711_1s_data[cycle_1s_cnt][HX711_4] = hx711_data[HX711_4];
        hx711_1s_data[cycle_1s_cnt][HX711_5] = hx711_data[HX711_5];
        hx711_1s_data[cycle_1s_cnt][HX711_6] = hx711_data[HX711_6];
        // sprintf(GlobalData,"[DEBUG] hx711 = %ld, %ld, %ld, %ld, %ld, %ld\n\r", hx711_data[HX711_1], hx711_data[HX711_2], hx711_data[HX711_3], hx711_data[HX711_4], hx711_data[HX711_5], hx711_data[HX711_6]);
        // cycle_1s_cnt = 49;
        //=========================红外 O2 CO2 DHT20=================================================
        if (cycle_1s_cnt == 0) {
            // O2氧气传感器发送查询指令
            unsigned char cmd_o2_density_read[8] = {0xFF, 0x03, 0x60, 0x01, 0x00, 0x01, 0xDE, 0x14};
            Usart_SendCommand(USART2, cmd_o2_density_read, 8);
            uart2_receive.index = 0;
        } else if (cycle_1s_cnt == 1) {
            // CO2氧气传感器发送查询指令
            unsigned char cmd_co2_density_read[8] = {0xFF, 0x03, 0x60, 0x01, 0x00, 0x01, 0xDE, 0x14};
            Usart_SendCommand(UART5, cmd_co2_density_read, 8);
            uart5_receive.index = 0;
        }
        else if (cycle_1s_cnt == 2) {
        } else if (cycle_1s_cnt == 3) {
            // DHT20温湿度初始化
            uint8_t statue = DHT20_Read_Status();
            if ((statue & 0x18) != 0x18) {
                DHT20_Start_Init(); // 重新初始化寄存器
            }
						DHT20_SendAC();
        } else if (cycle_1s_cnt == 4) {
            // 读取O2氧气传感器值
            if (uart2_receive.index == 7 && //
                uart2_receive.buff[0] == 0xFF && uart2_receive.buff[1] == 0x03 && uart2_receive.buff[2] == 0x02) {
                s_m4_o2.density_reg = (uart2_receive.buff[3] << 8) | uart2_receive.buff[4];
            }
            // 读取CO2氧气传感器值
            if (uart5_receive.index == 7 && //
                uart5_receive.buff[0] == 0xFF && uart5_receive.buff[1] == 0x03 && uart5_receive.buff[2] == 0x02) {
                s_m4_co2.density_reg = (uart5_receive.buff[3] << 8) | uart5_receive.buff[4];
            }
								
        } else if (cycle_1s_cnt == 5) {
            // O2发送小数点
            unsigned char cmd_o2_dot_read[8] = {0xFF, 0x03, 0x20, 0x31, 0x00, 0x01, 0xCB, 0xDB};
            Usart_SendCommand(USART2, cmd_o2_dot_read, 8);
            uart2_receive.index = 0;
        } else if (cycle_1s_cnt == 6) {
            // CO2发送小数点
            unsigned char cmd_co2_dot_read[8] = {0xFF, 0x03, 0x20, 0x31, 0x00, 0x01, 0xCB, 0xDB};
            Usart_SendCommand(UART5, cmd_co2_dot_read, 8);
            uart5_receive.index = 0;
        } else if (cycle_1s_cnt == 7) {
						
        } else if (cycle_1s_cnt == 8) {

        } else if (cycle_1s_cnt == 9) {
            // 读取DHT20的数据
            DHT20_Read_CTdata(dht20.CT_data);                                        // 不经过CRC校验，直接读取DHT20的温度和湿度数据    推荐每隔大于1S读一次
            dht20.humidity_x10 = dht20.CT_data[0] * 100 * 10 / 1024 / 1024;          // 计算得到湿度值c1（放大了10倍）
            dht20.temperature_x10 = dht20.CT_data[1] * 200 * 10 / 1024 / 1024 - 500; // 计算得到温度值t1（放大了10倍）
            dht20.humidity = dht20.humidity_x10 / 10.0;
            dht20.temperature = dht20.temperature_x10 / 10.0;
        } else if (cycle_1s_cnt == 10) {
            if (uart2_receive.index == 7 && //
                uart2_receive.buff[0] == 0xFF && uart2_receive.buff[1] == 0x03 && uart2_receive.buff[2] == 0x02) {
                s_m4_o2.dot_reg = (uart2_receive.buff[3] << 8) | uart2_receive.buff[4];
                s_m4_o2.density = s_m4_o2.density_reg / powf(10.0, s_m4_o2.dot_reg);
            }
        if (uart5_receive.index == 7 && //
                uart5_receive.buff[0] == 0xFF && uart5_receive.buff[1] == 0x03 && uart5_receive.buff[2] == 0x02) {
                s_m4_co2.dot_reg = (uart5_receive.buff[3] << 8) | uart5_receive.buff[4];
                s_m4_co2.density = s_m4_co2.density_reg / powf(10.0, s_m4_co2.dot_reg);
            }	
        } else if (cycle_1s_cnt == 11) {
    
        }
        //========================DHT20,CO2,O2,流量传感器,压力传感器数据初始化=========================================
        else if (cycle_1s_cnt == 12) {
            float sccm1, sccm2;
            sccm1 = (adc_value[0] / 4096.0 * 3.3 * 1.49129088 - 0.5) / 0.004;
            sccm2 = (adc_value[1] / 4096.0 * 3.3 * 1.49129088 - 0.5) / 0.004;
            if (sccm1 < 0) {
                sccm1 = 0;
            }
            if (sccm2 < 0) {
                sccm2 = 0;
            }
            sprintf(GlobalData, "< %d %.3f %.3f %07.2f %07.2f %04.0f %04.0f %d", //
                    id, dht20.humidity, dht20.temperature, s_m4_o2.density, s_m4_co2.density, sccm1, sccm2, counter_perv);
        } else if (cycle_1s_cnt == 13) {
            sprintf(GlobalData + strlen(GlobalData), //
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld",
                    hx711_1s_perv[0][HX711_1], hx711_1s_perv[0][HX711_2], hx711_1s_perv[0][HX711_3], hx711_1s_perv[0][HX711_4], hx711_1s_perv[0][HX711_5], hx711_1s_perv[0][HX711_6], //
                    hx711_1s_perv[1][HX711_1], hx711_1s_perv[1][HX711_2], hx711_1s_perv[1][HX711_3], hx711_1s_perv[1][HX711_4], hx711_1s_perv[1][HX711_5], hx711_1s_perv[1][HX711_6], //
                    hx711_1s_perv[2][HX711_1], hx711_1s_perv[2][HX711_2], hx711_1s_perv[2][HX711_3], hx711_1s_perv[2][HX711_4], hx711_1s_perv[2][HX711_5], hx711_1s_perv[2][HX711_6], //
                    hx711_1s_perv[3][HX711_1], hx711_1s_perv[3][HX711_2], hx711_1s_perv[3][HX711_3], hx711_1s_perv[3][HX711_4], hx711_1s_perv[3][HX711_5], hx711_1s_perv[3][HX711_6], //
                    hx711_1s_perv[4][HX711_1], hx711_1s_perv[4][HX711_2], hx711_1s_perv[4][HX711_3], hx711_1s_perv[4][HX711_4], hx711_1s_perv[4][HX711_5], hx711_1s_perv[4][HX711_6], //
                    hx711_1s_perv[5][HX711_1], hx711_1s_perv[5][HX711_2], hx711_1s_perv[5][HX711_3], hx711_1s_perv[5][HX711_4], hx711_1s_perv[5][HX711_5], hx711_1s_perv[5][HX711_6], //
                    hx711_1s_perv[6][HX711_1], hx711_1s_perv[6][HX711_2], hx711_1s_perv[6][HX711_3], hx711_1s_perv[6][HX711_4], hx711_1s_perv[6][HX711_5], hx711_1s_perv[6][HX711_6], //
                    hx711_1s_perv[7][HX711_1], hx711_1s_perv[7][HX711_2], hx711_1s_perv[7][HX711_3], hx711_1s_perv[7][HX711_4], hx711_1s_perv[7][HX711_5], hx711_1s_perv[7][HX711_6], //
                    hx711_1s_perv[8][HX711_1], hx711_1s_perv[8][HX711_2], hx711_1s_perv[8][HX711_3], hx711_1s_perv[8][HX711_4], hx711_1s_perv[8][HX711_5], hx711_1s_perv[8][HX711_6], //
                    hx711_1s_perv[9][HX711_1], hx711_1s_perv[9][HX711_2], hx711_1s_perv[9][HX711_3], hx711_1s_perv[9][HX711_4], hx711_1s_perv[9][HX711_5], hx711_1s_perv[9][HX711_6]);
        } else if (cycle_1s_cnt == 14) {
            sprintf(GlobalData + strlen(GlobalData), //
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld",
                    hx711_1s_perv[10][HX711_1], hx711_1s_perv[10][HX711_2], hx711_1s_perv[10][HX711_3], hx711_1s_perv[10][HX711_4], hx711_1s_perv[10][HX711_5], hx711_1s_perv[10][HX711_6], //
                    hx711_1s_perv[11][HX711_1], hx711_1s_perv[11][HX711_2], hx711_1s_perv[11][HX711_3], hx711_1s_perv[11][HX711_4], hx711_1s_perv[11][HX711_5], hx711_1s_perv[11][HX711_6], //
                    hx711_1s_perv[12][HX711_1], hx711_1s_perv[12][HX711_2], hx711_1s_perv[12][HX711_3], hx711_1s_perv[12][HX711_4], hx711_1s_perv[12][HX711_5], hx711_1s_perv[12][HX711_6], //
                    hx711_1s_perv[13][HX711_1], hx711_1s_perv[13][HX711_2], hx711_1s_perv[13][HX711_3], hx711_1s_perv[13][HX711_4], hx711_1s_perv[13][HX711_5], hx711_1s_perv[13][HX711_6], //
                    hx711_1s_perv[14][HX711_1], hx711_1s_perv[14][HX711_2], hx711_1s_perv[14][HX711_3], hx711_1s_perv[14][HX711_4], hx711_1s_perv[14][HX711_5], hx711_1s_perv[14][HX711_6], //
                    hx711_1s_perv[15][HX711_1], hx711_1s_perv[15][HX711_2], hx711_1s_perv[15][HX711_3], hx711_1s_perv[15][HX711_4], hx711_1s_perv[15][HX711_5], hx711_1s_perv[15][HX711_6], //
                    hx711_1s_perv[16][HX711_1], hx711_1s_perv[16][HX711_2], hx711_1s_perv[16][HX711_3], hx711_1s_perv[16][HX711_4], hx711_1s_perv[16][HX711_5], hx711_1s_perv[16][HX711_6], //
                    hx711_1s_perv[17][HX711_1], hx711_1s_perv[17][HX711_2], hx711_1s_perv[17][HX711_3], hx711_1s_perv[17][HX711_4], hx711_1s_perv[17][HX711_5], hx711_1s_perv[17][HX711_6], //
                    hx711_1s_perv[18][HX711_1], hx711_1s_perv[18][HX711_2], hx711_1s_perv[18][HX711_3], hx711_1s_perv[18][HX711_4], hx711_1s_perv[18][HX711_5], hx711_1s_perv[18][HX711_6], //
                    hx711_1s_perv[19][HX711_1], hx711_1s_perv[19][HX711_2], hx711_1s_perv[19][HX711_3], hx711_1s_perv[19][HX711_4], hx711_1s_perv[19][HX711_5], hx711_1s_perv[19][HX711_6]);
        } else if (cycle_1s_cnt == 15) {
            sprintf(GlobalData + strlen(GlobalData), //
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld",
                    hx711_1s_perv[20][HX711_1], hx711_1s_perv[20][HX711_2], hx711_1s_perv[20][HX711_3], hx711_1s_perv[20][HX711_4], hx711_1s_perv[20][HX711_5], hx711_1s_perv[20][HX711_6], //
                    hx711_1s_perv[21][HX711_1], hx711_1s_perv[21][HX711_2], hx711_1s_perv[21][HX711_3], hx711_1s_perv[21][HX711_4], hx711_1s_perv[21][HX711_5], hx711_1s_perv[21][HX711_6], //
                    hx711_1s_perv[22][HX711_1], hx711_1s_perv[22][HX711_2], hx711_1s_perv[22][HX711_3], hx711_1s_perv[22][HX711_4], hx711_1s_perv[22][HX711_5], hx711_1s_perv[22][HX711_6], //
                    hx711_1s_perv[23][HX711_1], hx711_1s_perv[23][HX711_2], hx711_1s_perv[23][HX711_3], hx711_1s_perv[23][HX711_4], hx711_1s_perv[23][HX711_5], hx711_1s_perv[23][HX711_6], //
                    hx711_1s_perv[24][HX711_1], hx711_1s_perv[24][HX711_2], hx711_1s_perv[24][HX711_3], hx711_1s_perv[24][HX711_4], hx711_1s_perv[24][HX711_5], hx711_1s_perv[24][HX711_6], //
                    hx711_1s_perv[25][HX711_1], hx711_1s_perv[25][HX711_2], hx711_1s_perv[25][HX711_3], hx711_1s_perv[25][HX711_4], hx711_1s_perv[25][HX711_5], hx711_1s_perv[25][HX711_6], //
                    hx711_1s_perv[26][HX711_1], hx711_1s_perv[26][HX711_2], hx711_1s_perv[26][HX711_3], hx711_1s_perv[26][HX711_4], hx711_1s_perv[26][HX711_5], hx711_1s_perv[26][HX711_6], //
                    hx711_1s_perv[27][HX711_1], hx711_1s_perv[27][HX711_2], hx711_1s_perv[27][HX711_3], hx711_1s_perv[27][HX711_4], hx711_1s_perv[27][HX711_5], hx711_1s_perv[27][HX711_6], //
                    hx711_1s_perv[28][HX711_1], hx711_1s_perv[28][HX711_2], hx711_1s_perv[28][HX711_3], hx711_1s_perv[28][HX711_4], hx711_1s_perv[28][HX711_5], hx711_1s_perv[28][HX711_6], //
                    hx711_1s_perv[29][HX711_1], hx711_1s_perv[29][HX711_2], hx711_1s_perv[29][HX711_3], hx711_1s_perv[29][HX711_4], hx711_1s_perv[29][HX711_5], hx711_1s_perv[29][HX711_6]);
        } else if (cycle_1s_cnt == 16) {
            sprintf(GlobalData + strlen(GlobalData), //
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld",
                    hx711_1s_perv[30][HX711_1], hx711_1s_perv[30][HX711_2], hx711_1s_perv[30][HX711_3], hx711_1s_perv[30][HX711_4], hx711_1s_perv[30][HX711_5], hx711_1s_perv[30][HX711_6], //
                    hx711_1s_perv[31][HX711_1], hx711_1s_perv[31][HX711_2], hx711_1s_perv[31][HX711_3], hx711_1s_perv[31][HX711_4], hx711_1s_perv[31][HX711_5], hx711_1s_perv[31][HX711_6], //
                    hx711_1s_perv[32][HX711_1], hx711_1s_perv[32][HX711_2], hx711_1s_perv[32][HX711_3], hx711_1s_perv[32][HX711_4], hx711_1s_perv[32][HX711_5], hx711_1s_perv[32][HX711_6], //
                    hx711_1s_perv[33][HX711_1], hx711_1s_perv[33][HX711_2], hx711_1s_perv[33][HX711_3], hx711_1s_perv[33][HX711_4], hx711_1s_perv[33][HX711_5], hx711_1s_perv[33][HX711_6], //
                    hx711_1s_perv[34][HX711_1], hx711_1s_perv[34][HX711_2], hx711_1s_perv[34][HX711_3], hx711_1s_perv[34][HX711_4], hx711_1s_perv[34][HX711_5], hx711_1s_perv[34][HX711_6], //
                    hx711_1s_perv[35][HX711_1], hx711_1s_perv[35][HX711_2], hx711_1s_perv[35][HX711_3], hx711_1s_perv[35][HX711_4], hx711_1s_perv[35][HX711_5], hx711_1s_perv[35][HX711_6], //
                    hx711_1s_perv[36][HX711_1], hx711_1s_perv[36][HX711_2], hx711_1s_perv[36][HX711_3], hx711_1s_perv[36][HX711_4], hx711_1s_perv[36][HX711_5], hx711_1s_perv[36][HX711_6], //
                    hx711_1s_perv[37][HX711_1], hx711_1s_perv[37][HX711_2], hx711_1s_perv[37][HX711_3], hx711_1s_perv[37][HX711_4], hx711_1s_perv[37][HX711_5], hx711_1s_perv[37][HX711_6], //
                    hx711_1s_perv[38][HX711_1], hx711_1s_perv[38][HX711_2], hx711_1s_perv[38][HX711_3], hx711_1s_perv[38][HX711_4], hx711_1s_perv[38][HX711_5], hx711_1s_perv[38][HX711_6], //
                    hx711_1s_perv[39][HX711_1], hx711_1s_perv[39][HX711_2], hx711_1s_perv[39][HX711_3], hx711_1s_perv[39][HX711_4], hx711_1s_perv[39][HX711_5], hx711_1s_perv[39][HX711_6]);
        } else if (cycle_1s_cnt == 17) {
            sprintf(GlobalData + strlen(GlobalData), //
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld"
                    " %ld %ld %ld %ld %ld %ld",
                    hx711_1s_perv[40][HX711_1], hx711_1s_perv[40][HX711_2], hx711_1s_perv[40][HX711_3], hx711_1s_perv[40][HX711_4], hx711_1s_perv[40][HX711_5], hx711_1s_perv[40][HX711_6], //
                    hx711_1s_perv[41][HX711_1], hx711_1s_perv[41][HX711_2], hx711_1s_perv[41][HX711_3], hx711_1s_perv[41][HX711_4], hx711_1s_perv[41][HX711_5], hx711_1s_perv[41][HX711_6], //
                    hx711_1s_perv[42][HX711_1], hx711_1s_perv[42][HX711_2], hx711_1s_perv[42][HX711_3], hx711_1s_perv[42][HX711_4], hx711_1s_perv[42][HX711_5], hx711_1s_perv[42][HX711_6], //
                    hx711_1s_perv[43][HX711_1], hx711_1s_perv[43][HX711_2], hx711_1s_perv[43][HX711_3], hx711_1s_perv[43][HX711_4], hx711_1s_perv[43][HX711_5], hx711_1s_perv[43][HX711_6], //
                    hx711_1s_perv[44][HX711_1], hx711_1s_perv[44][HX711_2], hx711_1s_perv[44][HX711_3], hx711_1s_perv[44][HX711_4], hx711_1s_perv[44][HX711_5], hx711_1s_perv[44][HX711_6], //
                    hx711_1s_perv[45][HX711_1], hx711_1s_perv[45][HX711_2], hx711_1s_perv[45][HX711_3], hx711_1s_perv[45][HX711_4], hx711_1s_perv[45][HX711_5], hx711_1s_perv[45][HX711_6], //
                    hx711_1s_perv[46][HX711_1], hx711_1s_perv[46][HX711_2], hx711_1s_perv[46][HX711_3], hx711_1s_perv[46][HX711_4], hx711_1s_perv[46][HX711_5], hx711_1s_perv[46][HX711_6], //
                    hx711_1s_perv[47][HX711_1], hx711_1s_perv[47][HX711_2], hx711_1s_perv[47][HX711_3], hx711_1s_perv[47][HX711_4], hx711_1s_perv[47][HX711_5], hx711_1s_perv[47][HX711_6], //
                    hx711_1s_perv[48][HX711_1], hx711_1s_perv[48][HX711_2], hx711_1s_perv[48][HX711_3], hx711_1s_perv[48][HX711_4], hx711_1s_perv[48][HX711_5], hx711_1s_perv[48][HX711_6], //
                    hx711_1s_perv[49][HX711_1], hx711_1s_perv[49][HX711_2], hx711_1s_perv[49][HX711_3], hx711_1s_perv[49][HX711_4], hx711_1s_perv[49][HX711_5], hx711_1s_perv[49][HX711_6]);
        } else if (cycle_1s_cnt == 18) {
        } else if (cycle_1s_cnt == 19) {
				}	else if (cycle_1s_cnt == 20) {
            if (uart1_receive.index == 2060 && //
                uart1_receive.buff[0] == 0x5a && uart1_receive.buff[1] == 0x5a) {
                int m_i, b_i;
                g9250.data_len = (uart1_receive.buff[3] << 8) | uart1_receive.buff[2];
                g9250.people_temperature = ((uart1_receive.buff[5] << 8) | uart1_receive.buff[4]) / 100.0;
                g9250.people_x = uart1_receive.buff[6];
                g9250.people_y = uart1_receive.buff[7];
                b_i = 8;
                for (m_i = 0; m_i < 1024; m_i++) {
                    g9250.matrix[m_i] = ((uart1_receive.buff[b_i + 1] << 8) | uart1_receive.buff[b_i]) / 100.0;
                    b_i = b_i + 2;
                }
            }
            sprintf(GlobalData + strlen(GlobalData), " %d %05.2f %d %d %05.2f", g9250.data_len, g9250.people_temperature, g9250.people_x, g9250.people_y, g9250.ic_temperature);
        } else if (cycle_1s_cnt == 21) {
						// 红外模式3
            uint8_t model3_cmd[4] = {0xA5, 0x55, 0x01, 0xFB};
            Usart_SendCommand(USART1, model3_cmd, 4);
            uart1_receive.index = 0;
        } else if (cycle_1s_cnt == 22) {
						g9250.spinrtf_start_index = 0;            // 红外发送读取整列指令
            uint8_t matrix_cmd[4] = {0xA5, 0x35, 0xF1, 0xCB};
            Usart_SendCommand(USART1, matrix_cmd, 4);
            uart1_receive.index = 0;
        } else if (23 <= cycle_1s_cnt && cycle_1s_cnt <= 47) {
            sprintf(GlobalData + strlen(GlobalData),
                    " %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f"                                                                                                                      //
                    " %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f"                                                                                                                      //
                    " %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f"                                                                                                                      //
                    " %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f",                                                                                                                     //
                    g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], //
                    g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], //
                    g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], //
                    g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++]);
        } else if (cycle_1s_cnt == 48) {
            sprintf(GlobalData + strlen(GlobalData),
                    " %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f" //
                    " %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f %05.2f" //
                    " %05.2f %05.2f %05.2f %05.2f >\n\r",                                    //
                    g9250.matrix[g9250.spinrtf_start_index++],
                    g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++],                     //
                    g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], //
                    g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++], g9250.matrix[g9250.spinrtf_start_index++]);
        } else if (cycle_1s_cnt == 49) {
            while (DMA_GetFlagStatus(DMA2_IT_TC5) == RESET);
            DMA_Cmd(DMA2_Channel5, DISABLE);
            DMA_ClearFlag(DMA2_IT_TC5);
            DMA_InitTypeDef DMA_InitStructure;
            GloblDataAll = strlen(GlobalData);
            GloblDataCont = 0;
            // 设置DMA源地址：串口数据寄存器地址*/
            DMA_InitStructure.DMA_PeripheralBaseAddr = (UART4_BASE + 0x04);
            // 内存地址(要传输的变量的指针)
            DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)GlobalData;
            // 方向：从内存到外设
            DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
            // 传输大小
            DMA_InitStructure.DMA_BufferSize = GloblDataAll;
            // 外设地址不增
            DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
            // 内存地址自增
            DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
            // 外设数据单位
            DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
            // 内存数据单位
            DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
            // DMA模式，一次或者循环模式
            DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
            //  优先级：中
            DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;
            // 禁止内存到内存的传输
            DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
            // 配置DMA通道
            DMA_Init(DMA2_Channel5, &DMA_InitStructure);
            DMA_Cmd(DMA2_Channel5, ENABLE);
        }
    }
}
